package com.zzy.pool.pool2.defaulttest1;

import java.io.IOException;

import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

public class TestPool2 {

	public static void main(String[] args) {

		GenericObjectPoolConfig conf = new GenericObjectPoolConfig();
		conf.setMaxTotal(20);
		conf.setMaxIdle(10);
		GenericObjectPool<StringBuffer> pool = new GenericObjectPool<StringBuffer>(new PooledStringBufferFactory(), conf);

		StringBuffer buf = null;
		try {
			buf = pool.borrowObject();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			throw new RuntimeException("Unable to borrow buffer from pool" + e.toString());
		} finally {
			try {
				if (null != buf) {
					pool.returnObject(buf);
				}
			} catch (Exception e) {
				// ignored
			}
		}
	}

}
